Dart Uri operator ==
Syntax & Examples
Uri.operator == operator
The `operator ==` in Dart checks if a URI is equal to another URI with the same normalized representation.
Syntax of Uri.operator ==
The syntax of Uri.operator == operator is:
operator ==(Object other) → boolThis operator == operator of Uri a URI is equal to another URI with the same normalized representation.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
|
✐ Examples
1 Comparing equal URIs
In this example,
- We create two URIs using `Uri.parse()` with the same normalized representation.
- We use the `==` operator to check if the URIs are equal.
- We then print the result of the comparison.
Dart Program
void main() {
Uri uri1 = Uri.parse('https://example.com');
Uri uri2 = Uri.parse('https://example.com');
bool isEqual = uri1 == uri2;
print('Are URIs equal? $isEqual');
}Output
Are URIs equal? true
2 Comparing unequal URIs
In this example,
- We create two URIs using `Uri.parse()` with different normalized representations.
- We use the `==` operator to check if the URIs are equal.
- We then print the result of the comparison.
Dart Program
void main() {
Uri uri1 = Uri.parse('https://example.com');
Uri uri2 = Uri.parse('https://anotherdomain.com');
bool isEqual = uri1 == uri2;
print('Are URIs equal? $isEqual');
}Output
Are URIs equal? false
3 Comparing URIs with different ports
In this example,
- We create two URIs using `Uri.parse()` with the same host but different ports.
- We use the `==` operator to check if the URIs are equal.
- We then print the result of the comparison.
Dart Program
void main() {
Uri uri1 = Uri.parse('https://example.com');
Uri uri2 = Uri.parse('https://example.com:443');
bool isEqual = uri1 == uri2;
print('Are URIs equal? $isEqual');
}Output
Are URIs equal? true
Summary
In this Dart tutorial, we learned about operator == operator of Uri: the syntax and few working examples with output and detailed explanation for each example.